package designpattern.abstractFactory;

import designpattern.factoryMethod.Room;
import designpattern.factoryMethod.Wall;
import designpattern.util.RefletUtil;
import designpattern.util.XMLUtil;

/**
 * 抽象工厂模式核心
 * with the Abstract Factory pattern,
 * a class delegates the responsibility of object instantiation to another object via composition
 */
public class Test {
    AbstractFactory abstractFactory;
    Room room;
    Wall wall;

    public Test(AbstractFactory abstractFactory) {
        this.abstractFactory = abstractFactory;
    }

    public void doSomething(){
        room=abstractFactory.getRoom();
        wall=abstractFactory.getWall();
        room.enter();
        wall.enter();
    }

    public static void main(String[] args) {
        System.out.println("-----------普通级别迷宫-------动作：进入房间、撞墙------");
        Test demo=new Test((AbstractFactory) RefletUtil.getObject(XMLUtil.getXMLContent("abstractFactoryclassName1")));
        demo.doSomething();
        System.out.println("-----------道具级别迷宫-------动作：进入房间、撞墙------");
        demo=new Test((AbstractFactory) RefletUtil.getObject(XMLUtil.getXMLContent("abstractFactoryclassName0")));
        demo.doSomething();
    }
}
